package com.ctvit.sjk.knowledge.user.controller;

import com.alibaba.fastjson2.JSON;
import com.ctvit.sjk.knowledge.core.controller.KnowledgeController;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 应用Controller
 *
 * @author heyingcheng
 * @date 2025/3/22
 */
@RestController
@RequestMapping("knowledge/user")
public class UserController extends KnowledgeController {

    /**
     * 查询用户信息
     */
    @GetMapping
    public AjaxResult get() {
        String userJsonText = "{\"id\":\"1\",\"username\":\"admin\",\"email\":\"\",\"role\":\"ADMIN\",\"permissions\":[\"APPLICATION:MANAGE:7191b580-0638-11f0-b029-0242ac110002\",\"APPLICATION:USE:7191b580-0638-11f0-b029-0242ac110002\",\"APPLICATION:DELETE:7191b580-0638-11f0-b029-0242ac110002\",\"DATASET:MANAGE:f0037f5e-061d-11f0-ab0f-0242ac110002\",\"DATASET:USE:f0037f5e-061d-11f0-ab0f-0242ac110002\",\"DATASET:DELETE:f0037f5e-061d-11f0-ab0f-0242ac110002\",\"DATASET:MANAGE:77f4a4da-06b7-11f0-b7ed-0242ac110002\",\"DATASET:USE:77f4a4da-06b7-11f0-b7ed-0242ac110002\",\"DATASET:DELETE:77f4a4da-06b7-11f0-b7ed-0242ac110002\",\"DATASET:MANAGE:fdfed186-061c-11f0-803d-0242ac110002\",\"DATASET:USE:fdfed186-061c-11f0-803d-0242ac110002\",\"DATASET:DELETE:fdfed186-061c-11f0-803d-0242ac110002\",\"APPLICATION:MANAGE:880f91e0-062b-11f0-ab0f-0242ac110002\",\"APPLICATION:USE:880f91e0-062b-11f0-ab0f-0242ac110002\",\"APPLICATION:DELETE:880f91e0-062b-11f0-ab0f-0242ac110002\",\"USER:READ\",\"USER:EDIT\",\"DATASET:CREATE\",\"DATASET:READ\",\"DATASET:EDIT\",\"APPLICATION:READ\",\"APPLICATION:CREATE\",\"APPLICATION:DELETE\",\"APPLICATION:EDIT\",\"SETTING:READ\",\"MODEL:READ\",\"MODEL:EDIT\",\"MODEL:DELETE\",\"MODEL:CREATE\",\"TEAM:READ\",\"TEAM:CREATE\",\"TEAM:DELETE\",\"TEAM:EDIT\"],\"is_edit_password\":false,\"language\":null}";
        return success(JSON.parse(userJsonText));
    }

    /**
     * 查询应用列表
     */
    @PostMapping("login")
    public AjaxResult login() {
        String loginUserKey = IdUtils.fastUUID();
        Map<String, Object> claims = new HashMap<>(1);
        claims.put(Constants.LOGIN_USER_KEY, loginUserKey);
        return toAjax(createToken(claims));
    }

    /**
     * 查询用户信息Pa
     */
    @GetMapping("list/{type}")
    public AjaxResult listByType(@PathVariable String type) {
        if ("APPLICATION".equals(type) || "DATASET".equals(type) || "FUNCTION".equals(type)) {
            String applicationJsonText = "[{\"id\":\"all\",\"username\":\"全部\"},{\"id\":\"my\",\"username\":\"我的\"}]";
            return success(JSON.parse(applicationJsonText));
        }
        return success();
    }

}
